extends TextureButton


var data = null



func set_data(data):
	self.data = data
	rect_position = Vector2(data["x"]+50000, data["y"]+50000)
	
	$Label.text = "【%s】Npc：%s" % [data["id"], data.get("name", "")]
	
	if data.get("npcRes", null):
		var texture = AtlasTexture.new()
		texture.atlas = load(data["npcRes"])
		texture.region = Rect2(0,0,32,32)
		
		self.texture_normal = texture
		self.texture_pressed = texture
		self.texture_hover = texture
		self.texture_disabled = texture
		self.texture_focused = texture


	

func _on_gui_input(event):
	if event is InputEventMouseButton:  
		if event.button_index == BUTTON_RIGHT and event.pressed:  
			# 鼠标右键被按下，弹出菜单
			var ui = MainTool.getUILayer().add_ui("res://tool/page/map/mapView/npc/NpcRightMenu.tscn", 0, true)
			ui.set_data(data)
			

func _on_MapNpc_button_up():
	var ui = MainTool.getUILayer().add_ui("res://tool/page/map/mapView/modal/MapNpcModal.tscn")
	ui.set_edit_data(data)

